<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="业务单打印" />
<%@ include file="../inc/PrintTitle.jsp"%>
<head>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doPrint(){
		ShowConfirm('确认框','确定开始打印吗？',340,80,"doPrintCallBack()");
	}
	function doPrintCallBack(){
		if(popRetVal!=null){
			document.getElementById("noPrinSpan").style.display="none";
			doPrintLog();
		}
	}
	function doCancel(){
		window.close();
	}
	function doPrintLog(){
		var cost="";
		var len=${fn:length(list)};
		for(var i=0;i<len;i++){
			if(cost!=""){
				cost=cost+";";
			}
			cost=cost+document.getElementById("cost_"+i).value;
		}
		var xmlHttp=createXMLHttpRequest();
		xmlHttp.open("GET", "/business/BusinessBillPrintLog.ihtm?id=${id}&type=BUS_COST&cost="+cost);
		xmlHttp.onreadystatechange = function(){callback(xmlHttp)};
		xmlHttp.send(null);
	}
	function callback(xmlHttp){
    	if (xmlHttp.readyState == 4) {
      		if (xmlHttp.status == 200) {
      			var resTxt=xmlHttp.responseText;
      			if(resTxt=="NO_LOGIN"){
      				ShowAlert('提示框','你还没登录或已经超时，请重新登录。',200,100);
      			}else if(resTxt=="OK"){
      				printContent("管理易-业务单","${enterpriseInfo.doPrint}","${enterpriseInfo.printWidth}");
      			}
      			document.getElementById("noPrinSpan").style.display="";
			}
		}
	}
	function printImageOnload(obj){
		obj.style.display="";//现在才显示，避免先会把页面撑大,再缩小
		obj.width=obj.width>500?500:obj.width;//要放在display后，否则width=0
	}
	//直接在合计处document.write在lodop会造成重复输出,改成设置innerHTML
	function showTotalDiv(imprest,favCost,cost,adjuCost,collCost,exam,divId){
		var str="";
		if(favCost==0){
			str=str+"&nbsp;<b>合计(大写):</b>";
		}else{
			str=str+"&nbsp;<b>优惠:</b>"+favCost+"</b>&nbsp;<b>折后合计(大写):</b>";
		}
		str=str+getBigMoney(""+cost);
		str=str+"<b>￥</b>"+cost+"&nbsp;";
		str=str+"<b>已调账:</b>"+adjuCost+"&nbsp;";
		str=str+"<b>已收款:</b>";
		if(exam=='Y'){
			str=str+collCost+"&nbsp;";
		}else{
			str=str+imprest+"&nbsp;";
		}
		str=str+"<b>尚欠金额:</b>";
		if(exam=='Y'){
			str=str+parseScale(abateMul(addMul(cost,adjuCost),collCost),2)+"&nbsp;";
		}else{
			str=str+parseScale(abateMul(addMul(cost,adjuCost),imprest),2)+"&nbsp;";
		}
		document.getElementById(divId).innerHTML=str;
	}
</script>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery-barcode.js"></script>
<script language="javascript">
	var settings = {
			output: "css",
          	showHRI: false,
          	bgColor: "#FFFFFF",
      		color: "#000000",
          	barWidth: 1,
          	barHeight: 30
	};
	//var btype="code39";
	var btype="code128";
	function showBarcode(value,objName){
		$("#"+objName).html("").show().barcode(value, btype, settings);
	}
</script>
</head>
<body style="background-color:#FFFFFF">
<c:forEach var="record" items="${list}" varStatus="bi">
<c:if test="${bi.index>0}"><div class='PageNext'>&nbsp;</div></c:if>
<input type="hidden" id="cost_${bi.index}" value="${record.businessBill.cost}">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td>
			<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
				<tr>
					<td width="16%" rowspan="2"><img src="${enterpriseInfo.loginImage}" /></td>
					<td width="68%" height="40px" align="center" class="FontLarge_Bold">${licenseInfo.enterpriseName} 业务单</td>
					<td width="16%">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="2" align="right" valign="bottom">
						<div id="barcodeTarget${bi.index}"></div>
						<div class="FontSmall" style="padding-right:8px;">${record.clientCode}&nbsp;&nbsp;NO.&nbsp;${record.businessBill.billCode}</div>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="ListTable">
				<tr class="ListTrPrint">
			      	<td class="FontSmall" width="70%">订货单位：${record.clientName}<c:if test="${record.busiPphone=='Y'}"> ${record.businessBill.linkman} ${record.businessBill.phone}</c:if></td>
			      	<td class="FontSmall" width="30%" align="right" style="padding-right:8px">订货日期：<fmt:formatDate value="${record.businessBill.orderDate}" pattern="yyyy-MM-dd"/></td>
				</tr>
				<tr class="ListTrPrint">
				  <td class="FontSmall">地址：<c:if test="${record.busiPphone=='Y'}">${record.businessBill.address}</c:if></td>
			      <td class="FontSmall" align="right" style="padding-right:8px">交货日期：<fmt:formatDate value="${record.businessBill.deliverDate}" pattern="yyyy-MM-dd"/></td>
			  </tr>
		  	</table>
		</td>
	</tr>
	<tr>
		<td height="3"></td>
	</tr>
	<tr>
		<td>
			<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="small_border">
				<tr class="ListTrPrint">
				  <td width="10%" height="23" class="FontSmall_Bold"><div align="center">项目类型</div></td>
				  <td width="16%" class="FontSmall_Bold"><div align="center">内容</div></td>
				  <td width="12%" class="FontSmall_Bold"><div align="center">材质</div></td>
				  <td width="14%" class="FontSmall_Bold"><div align="center">规格</div></td>
				  <td width="7%" class="FontSmall_Bold"><div align="center">单位</div></td>
				  <td width="8%" class="FontSmall_Bold"><div align="center">数量</div></td>
				  <td width="7%" class="FontSmall_Bold"><div align="center">单价</div></td>
				  <td width="10%" class="FontSmall_Bold"><div align="center">金额</div></td>
				  <td width="16%" class="FontSmall_Bold"><div align="center">制作要求</div></td>
				</tr>
				<c:forEach var="item" items="${record.items}" varStatus="i">
				<tr class="ListTrPrint">
				  <td class="FontSmall"><div align="center">${item.makeTypeName}</div></td>
				  <td class="FontSmall"><div align="center"><commonTag:parseEnterToBr source="${item.businessBillItem.finishedContent}" /></div></td>
				  <td class="FontSmall"><div align="center"><c:out value="${item.businessBillItem.proName}" /></div></td>
				  <td class="FontSmall">
					  <div align="center">
						  <commonTag:parseEnterToBr source="${item.businessBillItem.specification}" />
						  <c:if test="${item.businessBillItem.priceType=='AREA' || item.businessBillItem.priceType=='LENGTH'}"> x <commonTag:parseBigDecimal source="${item.businessBillItem.amount}" /></c:if>
					  </div>
				  </td>
				  <td class="FontSmall">
					  <div align="center">
					  	<c:if test="${item.businessBillItem.priceType=='AREA'}">平方米</c:if>
						<c:if test="${item.businessBillItem.priceType=='LENGTH'}">
							<c:if test="${item.businessBillItem.lengType=='M'}">米</c:if><c:if test="${item.businessBillItem.lengType=='CM'}">公分</c:if>
						</c:if>
						<c:if test="${item.businessBillItem.priceType=='AMOUNT'}">${item.businessBillItem.unit}</c:if>
					  </div>
				  </td>
				  <td class="FontSmall">
					  <div align="center">
					  	<c:if test="${item.businessBillItem.priceType=='AREA' || item.businessBillItem.priceType=='LENGTH'}"><commonTag:parseBigDecimal source="${item.businessBillItem.squareNum}" /></c:if>
						<c:if test="${item.businessBillItem.priceType=='AMOUNT'}"><commonTag:parseBigDecimal source="${item.businessBillItem.amount}" /></c:if>
					  </div>
				  </td>
				  <td class="FontSmall"><div align="center"><commonTag:parseBigDecimal source="${item.businessBillItem.unitPrice}" /></div></td>
				  <td class="FontSmall"><div align="center"><commonTag:parseBigDecimal source="${item.businessBillItem.cost}" /></div></td>
				  <td class="FontSmall"><div align="center"><commonTag:parseEnterToBr source="${item.businessBillItem.makeRequire}" /></div></td>

				</tr>
				</c:forEach>
			  	<tr class="ListTrPrint">
					<td class="FontSmall" colspan="9">
						<div align="right" id="totalDiv${bi.index}">&nbsp;</div>
					</td>
			  	</tr>	
		  </table>
		</td>
	</tr>
	<tr>
		<td height="3"></td>
	</tr>
	<tr>
		<td>
			<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="small_border">
				<c:if test="${enterpriseInfo.bbPrintImage=='Y' && fn:length(record.imgAccs)>0}">
		       	<c:forEach var="imgItem" items="${record.imgAccs}">
				<tr class="ListTrPrint">
					<td colspan="4" style="text-align:center"><img src="${imgItem.fileName}" style="display:none" onload="printImageOnload(this);"></td>
				</tr>
				</c:forEach>
				</c:if>
				<tr class="ListTrPrint">
					<td class="FontSmall_Bold" width="10%">提货要求</td>
			      	<td class="FontSmall" width="40%">${record.businessBill.ladingRequire}</td>
			      	<td class="FontSmall_Bold" width="10%">安装要求</td>
			      	<td class="FontSmall">${record.businessBill.setupRequire}</td>
				</tr>
				<tr class="ListTrPrint">
 			       	<td class="FontSmall_Bold" width="10%">备注</td>
			      	<td class="FontSmall" colspan="3">${record.businessBill.mark}</td>
				</tr>
		  </table>
		</td>
	</tr>
	<tr>
		<td height="3"></td>
	</tr>
	<tr>
		<td>
			<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center" class="ListTable">
				<tr class="ListTrPrint">
					<td class="FontSmall" width="20%">开单人:${record.businessBill.createrName}</td>
					<td class="FontSmall" width="20%">业务员:${record.businessBill.managerName}</td>
					<td class="FontSmall" width="20%">收款人:</td>
					<td class="FontSmall" width="20%">订货签字:</td>
					<td class="FontSmall" width="20%">提货签字:</td>
				</tr>
		  </table>
		</td>
	</tr>
	<tr>
		<td height="3"></td>
	</tr>
	<c:if test="${codeRule.printFoot!=null && codeRule.printFoot!=''}">
	<tr>
		<td>
			<table width="98%" border="0" cellspacing="1" cellpadding="1" align="center">
				<tr>
					<td class="FontSmall"><commonTag:parseEnterToBr source="${codeRule.printFoot}" /></td>
				</tr>
			</table>
		</td>
	</tr>
	</c:if>
</table>
<script language="javascript">
	showTotalDiv(${record.businessBill.imprest},${record.businessBill.favCost},${record.businessBill.cost},${record.businessBillExt.adjustCost},${record.businessBillExt.collectedCost},'${record.businessBillExt.examined}','totalDiv${bi.index}');
	<c:if test="${enterpriseInfo.busiBc=='Y'}">
		showBarcode('${record.businessBill.billCode}','barcodeTarget${bi.index}');
	</c:if>
</script>
</c:forEach>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="noPrinSpan">
	<tr>
		<td>
			<table width="98%" border="0" cellspacing="1" cellpadding="1" align="center">
				<tr>
					<td>
						<input type="button" id="printButton" class="Button" value="开始打印" onClick="doPrint();">
						<input type="button" id="cancelButton" class="Button" value=" 退 出 " onClick="doCancel();">
					</td>
				</tr>
				<tr>
					<td class="FontSmall" style="color:#666">提示：在系统管理菜单下，【系统配置】可以更改业务单打印的logo，可以设置是否打印效果图；【单据编号与页脚】可以定义业务单的单据流向及说明，例如写上：一式三联，白联留存，红联客户，黄联财务，服务监督电话：4006－XXX－XXX</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</body>
</html>